from django.shortcuts import render
from django.views.generic import View
from apps.goods.models import *
# Create your views here.

class IndexView(View):

    def get(self, request):
        # 获取数据
        # 全部商品分类
        all_category = GoodsCategory.objects.all()

        # 轮播商品
        banner_index = IndexGoodsBanner.objects.all()

        # hot商品
        hot_goods = IndexPromotionBanner.objects.all()

        # 促销活动
        limt_time = IndexLimitedTimeSaleForm.objects.all()

        # 首页列表展示
        types = GoodsType.objects.all()
        for type in types:
            # 获取type种类首页分类商品的图片信息
            print(type.name, type.id, type)
            image_banners = IndexTypeGoodsBanner.objects.filter(type=type, display_type=1).order_by('index')
            print(image_banners)
            # 获取type种类首页分类商品文字信息
            title_banners = IndexTypeGoodsBanner.objects.filter(type=type, display_type=0).order_by('index')

            # 获取分类活动图
            image = IndexGoodsTypeActivityImage.objects.filter(type_id=type, is_status=1)[:2]

            # 动态给type增加属性，分别保存首页分类商品的图片展示信息和文字信息
            type.image_banners = image_banners
            type.title_banners = title_banners
            type.huodong_image = image

        # 新闻资讯数据
        news_info = IndexNewsInfomations.objects.all()

        context = {
            'news_info': news_info,
            'all_category': all_category,
            'types': types,
            'banner_index': banner_index,
            # 'hot_goods': hot_goods,
            # 'limt_time': limt_time
        }

        return render(request,'index.html', context)








